import React from 'react'
import { useDispatch, useSelector } from 'react-redux'
import {increment,decrement,ifOddIncrement,waitIncrement} from '../../store/slice/countSlice'
export default function Count() {
    const dispatch = useDispatch()
    const count = useSelector(state => state.count.count)
    const incrementHandle = () => {
        dispatch(increment(1))
    }
    const decrementHandle = () => {
        dispatch(decrement(1))
    }
    const ifOddIncrementHandle = () => {
        if (count % 2 !== 0) {
            dispatch(ifOddIncrement(1))
        }
    }
    const waitIncrementHandle = () => {
        dispatch(waitIncrement(1))
    }
    return (
        <div>
            <h2>这是要累加的值{count}</h2>
            <button onClick={incrementHandle}>累加</button>
            <button onClick={decrementHandle}>累减</button>
            <button onClick={ifOddIncrementHandle}>奇数才加</button>
            <button onClick={waitIncrementHandle}>两秒后加</button>
        </div>
    )
}
